package com.ruoyi.edge.gateway.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.ruoyi.common.core.domain.R;
import com.ruoyi.common.mybatis.core.page.PageQuery;
import com.ruoyi.common.mybatis.core.page.TableDataInfo;
import com.ruoyi.edge.gateway.domain.Equipment;
import com.ruoyi.edge.gateway.mapper.EquipmentMapper;
import com.ruoyi.edge.gateway.service.EquipmentService;
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Service;

import java.util.List;

/**
 * 边缘计算设备管理
 */
@Slf4j
@RequiredArgsConstructor
@Service
public class EquipmentServiceImpl implements EquipmentService {

    private final EquipmentMapper equipmentMapper;

    @Override
    public TableDataInfo<Equipment> listPage(Equipment equipment, PageQuery pageQuery) {

        LambdaQueryWrapper<Equipment> lqw = new LambdaQueryWrapper<>();
        Page<Equipment> page = equipmentMapper.selectPage(pageQuery.build(), lqw);
        return TableDataInfo.build(page);
    }

    @Override
    public R<List<Equipment>> list(Equipment equipment) {
        LambdaQueryWrapper<Equipment> lqw = new LambdaQueryWrapper<>();
        List<Equipment> equipmentList = equipmentMapper.selectList(lqw);
        return R.ok(equipmentList);
    }

    @Override
    public R<Equipment> get(String id) {
        Equipment equipment = equipmentMapper.selectById(id);
        return R.ok(equipment);
    }

    @Override
    public R<String> add(Equipment equipment) {
        equipmentMapper.insert(equipment);
        return R.ok("新增成功");
    }

    @Override
    public R<String> edit(Equipment equipment) {
        equipmentMapper.updateById(equipment);
        return R.ok("修改成功");
    }

    @Override
    public R<String> remove(String id) {
        equipmentMapper.deleteById(id);
        return R.ok("删除成功");
    }

    @Override
    public R<String> editStatus(String id, Integer status) {
        equipmentMapper.editStatus(id, status);
        return R.ok("修改成功");
    }

}
